home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Arrays or Pointers?
- Date: 9 Apr 1996 07:48:34 GMT
- Organization: systems hk
- Message-ID: <4kd4oi$k1h@nadine.teleport.com>
- References: <4kbsk3$f07@zeus.tcp.co.uk>
- NNTP-Posting-Host: ip-pdx07-07.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- daveg@tcp.co.uk (David) wrote:
- >I'm currently on a C++ course and we seem to be using pointers a fair
- >bit. On questioning this, was told that pointers where quicker than
- >using arrays. In which situations should I be using arrays over
- >pointers and vice versa?
- >
- David,
- I prefer arrays under the following circumstances:
-
- 1) when it is easier to understand their use (i.e.: they model the
- real-world entity that is represented by them).
- 2) speed is not a high-order issue.
- 3) when I need guarantee of contiguous data (i.e.: array[0],[1],...)
-
- You can usually use a combination of the two syntaxes when the
- pointers refer to contiguous, constant-length, aggregates.
- (i.e.: 'letter = string[12];' can usually stand in for: 'letter = *(string+12);')
-
- Yours, Geoff Houck
-
-